<template>
	<view>

		<!-- <u-modal :show="show" :title="title" :content='content' :showConfirmButton='false'>
			<view v-for="(item,index) in userName" :key="index">
				{{item}}
			</view>
		</u-modal> -->


		<view class="toux">
			<image src="../../static/logo.png" mode="" style="width: 160rpx;height: 160rpx;border-radius: 50%;">
			</image>
			<view style="margin-top: 20rpx; font-weight: 700;">来哔滴-商家端</view>
		</view>
		<view class="user">
			<u-form :model="form" ref="uForm">
				<u-form-item prop="name" leftIcon="account" leftIconStyle="color:#3A62D7;font-size:40rpx;">
					<u-input v-model="form.name" placeholder="请输入账号" border='bottom' />
				</u-form-item>
				<u-form-item prop="name" leftIcon="lock" leftIconStyle="color:#3A62D7;font-size:40rpx;">
					<u-input v-model="form.password" placeholder="请输入密码" border='bottom' type='password' />
				</u-form-item>

			</u-form>
			<view class="btn" @click="wxLogin()">
				登录
			</view>
			<view class="xiey">
				<view style="display: flex;justify-content: space-between;">
					<view @click="todelPws">
						忘记密码？
					</view>
					<view @click="toreg">
						注册
					</view>
				</view>
				<view style="display: flex;margin-top: 20rpx;font-size: 22rpx;">
					<u-checkbox-group>
						<u-checkbox v-model="checked" shape="circle" @change="check"></u-checkbox>
					</u-checkbox-group>
					<view>
						已阅读协议
					</view>
					<navigator url="/pages/sub/user/settingInfo?name=master_agreement"
						style="color:#3A62D7 ;margin-left: -4rpx;">《用户协议》</navigator>
				</view>

			</view>
		</view>

	</view>
</template>

<script>
	import {
		login,
		getConfigList
	} from "@/api/common.js";
	export default {
		data() {
			return {
				checked: false,
				imgs: '',
				form: {
					name: '',
					password: '',
				},
				rules: {
					// name: [{
					// 	required: true,
					// 	message: '请输入账号',
					// 	// 可以单个或者同时写两个触发验证方式 
					// 	trigger: ['change', 'blur']
					// }],
					// password: [{
					// 	required: true,
					// 	message: '请输入密码',
					// 	// 可以单个或者同时写两个触发验证方式 
					// 	trigger: ['change', 'blur']
					// }]
				}
			}
		},
		onLoad() {
			// this.getConfigLists()
		},
		onReady() {
			// this.$refs.uForm.setRules(this.rules);
			// this.$refs.passform.setRules(this.rules);
		},
		methods: {
			wxLogin() {
				if (this.checked == false) {
					return uni.showToast({
						title: "请勾选协议",
						icon: 'none'
					})
				}
				let that = this
				uni.getUserProfile({
					desc: "获取用户基本资料",
					lang: 'zh_CN',
					success: (user) => {
						//获取成功基本资料后开启登录，因为基本资料首先要授权

						uni.login({
							provider: 'weixin',
							success: function(code_res) {
								if (code_res.errMsg == "login:ok") {

									let code = code_res.code;
									let params = {
										code: code,
										account: that.form.name,
										pwd: that.form.password
									}

									params = Object.assign(params, user.userInfo)

									login(params).then(res => {
										console.log('token<><<<<<<', JSON.stringify(res
											.data));
										that.$store.commit("LOGIN", res.data);
										if (res.code == 200) {
											uni.showToast({
												title: "登录成功",
												icon: 'none'
											})
											uni.switchTab({
												url: "/pages/daren/index",
											})
										}
									})

								}
							}
						});

					},
					fail: (res) => {
						uni.showModal({
							title: "用户拒绝授权",
							showCancel: false
						})
					}
				});
			},
			//登录logo
			// getConfigLists() {
			// 	getConfigList({
			// 		key: 'login_logo'
			// 	}).then(res => {
			// 		this.imgs = res.data.value
			// 		console.log("111111", res.data);
			// 	})
			// },
			toreg() {
				uni.navigateTo({
					url: "/pages/login/register"
				})
			},
			login() {
				if (this.form.name !== "" && this.form.password !== "" && this.checked == true) {
					login({
						account: this.form.name,
						pwd: this.form.password
					}).then(res => {
						console.log('token<><<<<<<', JSON.stringify(res.data));
						this.$store.commit("LOGIN", res.data);
						if (res.code == 200) {
							uni.showToast({
								title: "登录成功",
								icon: 'none'
							})
							uni.switchTab({
								url: "/pages/daren/index",
							})
						}
					})
				} else if (this.checked == false) {
					uni.showToast({
						title: "请勾选协议",
						icon: 'none'
					})
				}
			},
			check() {
				this.checked = !this.checked;
			},
			todelPws() {
				uni.navigateTo({
					url: "/pages/login/updataPad"
				})
			},

		},
	}
</script>

<style lang="scss">
	page {
		font-size: 30rpx;
	}
</style>
<style lang="scss" scoped>
	.u-form-item__body__right__message {
		margin-left: 0;
	}

	.toux {
		position: absolute;
		top: 18%;
		left: 38%;
		text-align: center;

		.img {
			width: 268rpx;
			height: 268rpx;
			border-radius: 146rpx;
		}

		.text {
			margin-top: 30rpx;
			font-size: 24px;
			font-weight: 700;
		}

		.xiahua {
			width: 148rpx;
			height: 4rpx;
			background-color: #3A62D7;
			margin: 20rpx 0 0 60rpx;
		}
	}

	.user {
		width: 80%;
		position: absolute;
		top: 600rpx;
		left: 54rpx;

		.zhang {
			display: flex;
			align-items: center;
			margin: 50rpx 0;
			width: 83%;
			margin-left: 44px;
			border-bottom: 1px solid rgb(231, 231, 231);

			.u-border {
				border-style: none
			}

			.iconbox {
				width: 60rpx;

			}

			.paicon {
				position: absolute;
				top: 140rpx;
				left: 88rpx;
			}


			.u-form {
				flex: 1;
			}
		}
	}

	/deep/.u-form-item__body__right__message {
		font-size: 14px;
		margin-left: 18rpx;
	}

	.btn {
		width: 86%;
		height: 80rpx;
		background-color: #3A62D7;
		color: #fff;
		line-height: 80rpx;
		text-align: center;
		margin: 60rpx 0 0 84rpx;
	}

	.xiey {
		font-size: 22rpx;

		margin: 30rpx 0 0 84rpx;
	}
</style>